package com.zc.webnews.utils;


import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * "http://rss.sina.com.cn/sina_all_opml.xml"
 * Created by Administrator on 2016/11/15.
 */
public class HttpUrlUtils {
    private static HttpUrlUtils httpUrlUtils = null;
    public HttpUrlUtils(){

    }
    public static HttpUrlUtils getInstance(){
        if (httpUrlUtils == null){
            synchronized (HttpUrlUtils.class){
                if (httpUrlUtils == null){
                    httpUrlUtils = new HttpUrlUtils();
                    return httpUrlUtils;
                }

            }
        }
        return  httpUrlUtils;
    }

    public InputStream getInputStream(String path){
        InputStream input = null;
        try {
            URL url = new URL(path);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setDoInput(true);
            input = connection.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return input;
    }
}
